mod handler;
mod middleware;
mod state;

use std::sync::Arc;

use axum::{middleware::from_extractor_with_state, routing::get, Router};
use middleware::Auth as AuthExtractor;
pub use state::AppState;
use tokio::net::TcpListener;

#[tokio::main]
async fn main() {
    let state = Arc::new(AppState {
        version: Arc::new("v0.1.0".to_string()),
    });

    let app = Router::new()
        .route("/", get(handler::index))
        .layer(from_extractor_with_state::<AuthExtractor, Arc<AppState>>(
            state.clone(),
        ))
        .with_state(state);

    let tcp_listener = TcpListener::bind("0.0.0.0:56789").await.unwrap();

    axum::serve(tcp_listener, app).await.unwrap();
}
